const config = require("../../config");

class PreparePost {
    constructor(obj) {
        this.title = obj.title;
        this.content = obj.content;
        this.imgCount = obj.imgCount || 0;
        this.type = obj.type;
    }

    check() {
        let title = this.title;
        if (!title) {
            return { success: false, err: '标题为空' };
        }
        if (title.length > 100) {
            return { success: false, err: '标题长度不能超过 100 个字符' };
        }
        let content = this.content;
        if (content.length > 50000) {
            return { success: false, err: '内容为空' };
        }
        let imgCount = parseInt(this.imgCount);
        if (imgCount === NaN) {
            imgCount = 0;
        }
        if (imgCount < 0 || imgCount > config.community.postImageMaxCount) {
            return { success: false, err: '图片数量超出范围' };
        }
        if (!this.type) {
            return { success: false, err: '动态类型不能为空' };
        }
        return { success: true };
    }
}

module.exports = PreparePost;